package com.hctforgreen.greenservice.examine;

import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.TextView;

import com.hctforgreen.greenservice.ParentActivity;
import com.hctforgreen.greenservice.R;
import com.hctforgreen.greenservice.model.ExamSubEntity;
import com.hctforgreen.greenservice.service.HctApplication;
import com.hctforgreen.greenservice.ui.adapter.ShowSituationListAdapter;
import com.hctforgreen.greenservice.utils.HctConstants;

/**
 * 答题列表
 * 
 * @author Tallen Zhai
 * 
 */
public class ShowSituationListActivity extends ParentActivity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.show_situation_lst_activity);
		initSkinLayout();
		initFinshExamineActivityReceiver();
		Intent intent = getIntent();
		// AllExamListEntity listEntity = (AllExamListEntity) intent
		// .getSerializableExtra(HctConstants.ON_ACTIVITY_KEY_ALL_EXAM_LIST_ENTITY);

		initTitleButtonBar();
		initWindow();
	}

	private void initTitleButtonBar() {
		final TextView titleTv = (TextView) findViewById(R.id.tv_title);
		titleTv.setText(getString(R.string.answer_analysis_title));

		final ImageButton backBtn = (ImageButton) findViewById(R.id.btn_back);
		backBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}
		});
		// InitTitle.initTitle(this, R.drawable.btn_reback, "答题列表", 0,
		// new OnClickListener() {
		// @Override
		// public void onClick(View v) {
		// finish();
		// }
		//
		// }, null);
	}

	private void initWindow() {
		List<ExamSubEntity> listEntity = HctApplication.examSubEntities;
		renderNumHint(listEntity);
		HctApplication.examSubEntities = null;
		GridView notYetGv = (GridView) findViewById(R.id.gv_not_yet);
		new ShowSituationListAdapter(this, notYetGv, listEntity);
	}

	private void renderNumHint(List<ExamSubEntity> listEntity) {
		final TextView subNumTv = (TextView) findViewById(R.id.tv_sub_num);
		final TextView rightNumTv = (TextView) findViewById(R.id.tv_right_num);
		final TextView wrongNumTv = (TextView) findViewById(R.id.tv_wrong_num);
		final TextView emptyNumTv = (TextView) findViewById(R.id.tv_empty_num);
		subNumTv.setText(String.valueOf(listEntity.size()));
		int iRightNum = 0;
		int iWrongNum = 0;
		int iEmptyNum = 0;
		for (ExamSubEntity examEntity : listEntity) {
			if (examEntity.inputAnswerResult
					.equals(HctConstants.INPUT_ANSWER_RESULT_ALL_RIGHT)) {
				iRightNum++;
			} else if (examEntity.inputAnswerResult
					.equals(HctConstants.INPUT_ANSWER_RESULT_HALF_RIGHT)
					|| examEntity.inputAnswerResult
							.equals(HctConstants.INPUT_ANSWER_RESULT_ALL_WRONG)) {
				iWrongNum++;
			} else if (examEntity.inputAnswerResult
					.equals(HctConstants.INPUT_ANSWER_RESULT_EMPTY)) {
				iEmptyNum++;
			}
		}
		rightNumTv.setText(String.valueOf(iRightNum));
		wrongNumTv.setText(String.valueOf(iWrongNum));
		emptyNumTv.setText(String.valueOf(iEmptyNum));
	}
}
